home *** CD-ROM | disk | FTP | other *** search
/ Network PC / Network PC.iso / amiga utilities / communication / bbs / termv4.6 / extras / source / term-source.lha / PickDisplayMode.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-18  |  7.7 KB  |  340 lines

  1. /*
  2. **    PickDisplayMode.c
  3. **
  4. **    User interface for selecting screen display modes
  5. **
  6. **    Copyright © 1990-1996 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. */
  9.  
  10. #ifndef _GLOBAL_H
  11. #include "Global.h"
  12. #endif
  13.  
  14. enum    { GAD_USE=1000,GAD_CANCEL };
  15.  
  16. STATIC ULONG __asm
  17. FilterModeID(REG(d0) ULONG ID,REG(a0) APTR UserData)
  18. {
  19.     struct DimensionInfo DimensionInfo;
  20.  
  21.     if(GetDisplayInfoData(NULL,(APTR)&DimensionInfo,sizeof(struct DimensionInfo),DTAG_DIMS,ID))
  22.     {
  23.         if(DimensionInfo.MaxDepth >= (LONG)UserData && DimensionInfo.MaxDepth <= 8)
  24.             return(TRUE);
  25.     }
  26.  
  27.     return(FALSE);
  28. }
  29.  
  30.     /* PickDisplayMode(struct Window *Parent,ULONG *CurrentMode,struct Configuration *Config):
  31.      *
  32.      *    Pick a screen display mode from a list. If the Config pointer is not NULL,
  33.      *    will filter display modes out which cannot be used for the `term' main
  34.      *    screen, given the current colour restrictions.
  35.      */
  36.  
  37. BOOL
  38. PickDisplayMode(struct Window *Parent,ULONG *CurrentMode,struct Configuration *Config)
  39. {
  40.     BOOL Success = FALSE;
  41.     LONG MinDepth;
  42.  
  43.     if(Config)
  44.     {
  45.         switch(Config -> ScreenConfig -> ColourMode)
  46.         {
  47.             case COLOUR_AMIGA:
  48.  
  49.                 MinDepth = 2;
  50.                 break;
  51.  
  52.             case COLOUR_EIGHT:
  53.  
  54.                 MinDepth = 3;
  55.                 break;
  56.  
  57.             case COLOUR_SIXTEEN:
  58.  
  59.                 MinDepth = 4;
  60.                 break;
  61.  
  62.             case COLOUR_MONO:
  63.  
  64.                 MinDepth = 1;
  65.                 break;
  66.         }
  67.     }
  68.  
  69.         // For poor Workbench 2.04 users...
  70.  
  71.     if(AslBase -> lib_Version < 38)
  72.     {
  73.         struct List    *ModeList;
  74.         LONG         Index;
  75.  
  76.         if(ModeList = BuildModeList(&Index,*CurrentMode,Config ? FilterModeID : NULL,(APTR)MinDepth))
  77.         {
  78.             struct LayoutHandle *Handle;
  79.  
  80.             if(Handle = LT_CreateHandleTags(Parent -> WScreen,
  81.                 LH_LocaleHook,    &LocaleHook,
  82.             TAG_DONE))
  83.             {
  84.                 struct Window *LocalWindow;
  85.  
  86.                 LT_New(Handle,
  87.                     LA_Type,VERTICAL_KIND,
  88.                 TAG_DONE);
  89.                 {
  90.                     LT_New(Handle,
  91.                         LA_Type,VERTICAL_KIND,
  92.                     TAG_DONE);
  93.                     {
  94.                         LONG MaxWidth = -1,MaxHeight = 0,Len;
  95.                         struct Node *Node;
  96.  
  97.                         for(Node = ModeList -> lh_Head ; Node -> ln_Succ ; Node = Node -> ln_Succ)
  98.                         {
  99.                             Len = strlen(Node -> ln_Name);
  100.  
  101.                             if(Len > MaxWidth)
  102.                                 MaxWidth = Len;
  103.  
  104.                             MaxHeight++;
  105.                         }
  106.  
  107.                         MaxHeight++;
  108.  
  109.                         LT_New(Handle,
  110.                             LA_Type,    LISTVIEW_KIND,
  111.                             LA_LabelID,    MSG_V36_0160,
  112.                             GTLV_Labels,    ModeList,
  113.                             LA_LONG,    &Index,
  114.                             LALV_CursorKey,    TRUE,
  115.                             LALV_Link,    NIL_LINK,
  116.                             LALV_MaxGrowY,    MaxHeight,
  117.                             LALV_ResizeY,    TRUE,
  118.                             LA_Lines,    MaxHeight > 10 ? 10 : MaxHeight,
  119.                             LA_Chars,    MaxWidth,
  120.                             LA_CursorKey,    TRUE,
  121.                         TAG_DONE);
  122.  
  123.                         LT_EndGroup(Handle);
  124.                     }
  125.  
  126.                     LT_New(Handle,
  127.                         LA_Type,VERTICAL_KIND,
  128.                     TAG_DONE);
  129.                     {
  130.                         LT_New(Handle,
  131.                             LA_Type,    XBAR_KIND,
  132.                             LAXB_FullSize,    TRUE,
  133.                         TAG_DONE);
  134.  
  135.                         LT_EndGroup(Handle);
  136.                     }
  137.  
  138.                     LT_New(Handle,LA_Type,HORIZONTAL_KIND,
  139.                         LAGR_SameSize,    TRUE,
  140.                         LAGR_Spread,    TRUE,
  141.                     TAG_DONE);
  142.                     {
  143.                         LT_New(Handle,
  144.                             LA_Type,    BUTTON_KIND,
  145.                             LA_LabelID,    MSG_GLOBAL_USE_GAD,
  146.                             LA_ID,        GAD_USE,
  147.                             LABT_ReturnKey,    TRUE,
  148.                             LABT_ExtraFat,    TRUE,
  149.                         TAG_DONE);
  150.  
  151.                         LT_New(Handle,
  152.                             LA_Type,    BUTTON_KIND,
  153.                             LA_LabelID,    MSG_GLOBAL_CANCEL_GAD,
  154.                             LA_ID,        GAD_CANCEL,
  155.                             LABT_EscKey,    TRUE,
  156.                             LABT_ExtraFat,    TRUE,
  157.                         TAG_DONE);
  158.  
  159.                         LT_EndGroup(Handle);
  160.                     }
  161.  
  162.                     LT_EndGroup(Handle);
  163.                 }
  164.  
  165.                 if(LocalWindow = LT_Build(Handle,
  166.                     LAWN_TitleID,        MSG_V36_0161,
  167.                     LAWN_IDCMP,        IDCMP_CLOSEWINDOW,
  168.                     LAWN_HelpHook,        &GuideHook,
  169.                     LAWN_Parent,        Parent,
  170.                     WA_DepthGadget,        TRUE,
  171.                     WA_CloseGadget,        TRUE,
  172.                     WA_DragBar,        TRUE,
  173.                     WA_RMBTrap,        TRUE,
  174.                     WA_Activate,        TRUE,
  175.                     WA_SimpleRefresh,    TRUE,
  176.                 TAG_DONE))
  177.                 {
  178.                     struct IntuiMessage    *Message;
  179.                     ULONG             MsgClass;
  180.                     struct Gadget        *MsgGadget;
  181.                     LONG             i;
  182.                     struct ModeNode        *ModeNode;
  183.                     BOOL             Done = FALSE;
  184.  
  185.                     do
  186.                     {
  187.                         WaitPort(LocalWindow -> UserPort);
  188.  
  189.                         while(Message = (struct IntuiMessage *)LT_GetIMsg(Handle))
  190.                         {
  191.                             MsgClass    = Message -> Class;
  192.                             MsgGadget    = (struct Gadget *)Message -> IAddress;
  193.  
  194.                             LT_ReplyIMsg(Message);
  195.  
  196.                             if(MsgClass == IDCMP_CLOSEWINDOW)
  197.                                 Done = TRUE;
  198.  
  199.                             if(MsgClass == IDCMP_GADGETUP)
  200.                             {
  201.                                 switch(MsgGadget -> GadgetID)
  202.                                 {
  203.                                     case GAD_USE:
  204.  
  205.                                         for(ModeNode = (struct ModeNode *)ModeList -> lh_Head, i = 0; ModeNode -> VanillaNode . ln_Succ ; ModeNode = (struct ModeNode *)ModeNode -> VanillaNode . ln_Succ, i++)
  206.                                         {
  207.                                             if(Index == i)
  208.                                             {
  209.                                                 *CurrentMode = ModeNode -> DisplayID;
  210.  
  211.                                                 break;
  212.                                             }
  213.                                         }
  214.  
  215.                                         Success = Done = TRUE;
  216.                                         break;
  217.  
  218.                                     case GAD_CANCEL:
  219.  
  220.                                         Done = TRUE;
  221.                                         break;
  222.                                 }
  223.                             }
  224.  
  225.                             if(MsgClass == IDCMP_IDCMPUPDATE)
  226.                             {
  227.                                 for(ModeNode = (struct ModeNode *)ModeList -> lh_Head, i = 0; ModeNode -> VanillaNode . ln_Succ ; ModeNode = (struct ModeNode *)ModeNode -> VanillaNode . ln_Succ, i++)
  228.                                 {
  229.                                     if(Index == i)
  230.                                     {
  231.                                         *CurrentMode = ModeNode -> DisplayID;
  232.  
  233.                                         Success = Done = TRUE;
  234.  
  235.                                         LT_PressButton(Handle,GAD_USE);
  236.  
  237.                                         break;
  238.                                     }
  239.                                 }
  240.                             }
  241.                         }
  242.                     }
  243.                     while(!Done);
  244.  
  245.                     if(Success && Config)
  246.                     {
  247.                         Config -> ScreenConfig -> Depth        = 0;
  248.                         Config -> ScreenConfig -> OverscanType    = OSCAN_TEXT;
  249.                         Config -> ScreenConfig -> DisplayWidth    = 0;
  250.                         Config -> ScreenConfig -> DisplayHeight    = 0;
  251.                     }
  252.                 }
  253.  
  254.                 LT_DeleteHandle(Handle);
  255.             }
  256.  
  257.             DeleteList(ModeList);
  258.         }
  259.     }
  260.     else
  261.     {
  262.         LONG            DisplayWidth,
  263.                     DisplayHeight,
  264.                     Depth,
  265.                     OverscanType;
  266.         struct Rectangle    DisplayClip;
  267.  
  268.         struct TagItem             DimensionTags[5];
  269.         struct ScreenModeRequester    *Request;
  270.  
  271.         if(Config)
  272.         {
  273.             Depth = Config -> ScreenConfig -> Depth;
  274.  
  275.             if(Depth < MinDepth)
  276.                 Depth = MinDepth;
  277.  
  278.             OverscanType = Config -> ScreenConfig -> OverscanType;
  279.  
  280.             if((!Config -> ScreenConfig -> DisplayWidth || !Config -> ScreenConfig -> DisplayHeight) && QueryOverscan(Config -> ScreenConfig -> DisplayMode,&DisplayClip,OverscanType))
  281.             {
  282.                 DisplayWidth    = DisplayClip . MaxX - DisplayClip . MinX + 1;
  283.                 DisplayHeight    = DisplayClip . MaxY - DisplayClip . MinY + 1;
  284.             }
  285.             else
  286.             {
  287.                 DisplayWidth    = Config -> ScreenConfig -> DisplayWidth;
  288.                 DisplayHeight    = Config -> ScreenConfig -> DisplayHeight;
  289.             }
  290.         }
  291.         else
  292.             DisplayWidth = DisplayHeight = 0;
  293.  
  294.         if(Request = (struct ScreenModeRequester *)AllocAslRequestTags(ASL_ScreenModeRequest,
  295.             ASLSM_Window,            Parent,
  296.             ASLSM_InitialDisplayID,        *CurrentMode,
  297.             ASLSM_PrivateIDCMP,        TRUE,
  298.  
  299.             Config ? ASLSM_InitialDisplayDepth        : TAG_IGNORE,    Depth,
  300.             Config ? ASLSM_MinDepth                : TAG_IGNORE,    MinDepth,
  301.             Config ? ASLSM_MaxDepth                : TAG_IGNORE,    8,
  302.             Config ? ASLSM_DoDepth                : TAG_IGNORE,    TRUE,
  303.             Config ? ASLSM_DoWidth                : TAG_IGNORE,    TRUE,
  304.             Config ? ASLSM_DoHeight                : TAG_IGNORE,    TRUE,
  305.             Config ? ASLSM_DoOverscanType            : TAG_IGNORE,    TRUE,
  306.             Config ? ASLSM_InitialOverscanType        : TAG_IGNORE,    OverscanType,
  307.  
  308.             DisplayWidth  ? ASLSM_InitialDisplayWidth    : TAG_IGNORE,    DisplayWidth,
  309.             DisplayHeight ? ASLSM_InitialDisplayHeight    : TAG_IGNORE,    DisplayHeight,
  310.         TAG_MORE,GetDimensionTags(Parent,DimensionTags)))
  311.         {
  312.             if(AslRequest(Request,NULL))
  313.             {
  314.                 PutDimensionTags(Parent,Request -> sm_LeftEdge,Request -> sm_TopEdge,Request -> sm_Width,Request -> sm_Height);
  315.  
  316.                 *CurrentMode = Request -> sm_DisplayID;
  317.  
  318.                 if(Config)
  319.                 {
  320.                     if(Request -> sm_DisplayDepth == MinDepth)
  321.                         Depth = 0;
  322.                     else
  323.                         Depth = Request -> sm_DisplayDepth;
  324.  
  325.                     Config -> ScreenConfig -> Depth        = Depth;
  326.                     Config -> ScreenConfig -> OverscanType    = Request -> sm_OverscanType;
  327.                     Config -> ScreenConfig -> DisplayWidth    = Request -> sm_DisplayWidth;
  328.                     Config -> ScreenConfig -> DisplayHeight    = Request -> sm_DisplayHeight;
  329.                 }
  330.  
  331.                 Success = TRUE;
  332.             }
  333.  
  334.             FreeAslRequest(Request);
  335.         }
  336.     }
  337.  
  338.     return(Success);
  339. }
  340.